package com.csj.mvvmtest.ui.third

import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import com.csj.mvvm.ui.base.BaseFragment
import com.csj.mvvmtest.bean.ThirdBean
import com.csj.mvvmtest.databinding.FragmentThirdBinding

class ThirdFragment : BaseFragment<ThirdModel, FragmentThirdBinding>() {
    private var adapter: ThirdAdapter? = null
    private var list: ArrayList<ThirdBean.DataBean> = ArrayList()

    override fun initClick() {
    }

    override fun initData() {
        adapter = ThirdAdapter(mContext, list)
        v.rv.layoutManager = LinearLayoutManager(mContext)
        v.rv.adapter = adapter

        v.refreshLayout.setOnRefreshListener {//下拉刷新
            vm.getData()
        }
        v.refreshLayout.setEnableLoadMore(false)
    }

    override fun initVM() {
        vm.articlesData.observe(this, Observer {
            v.refreshLayout.finishRefresh()
            adapter!!.replaceData(it.data)
        })
    }

    override fun lazyLoadData() {
        vm.getData()
    }
}